package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import po.User;

public class SuperDao extends BaseDAO implements ISuperDao{
	public List<User> findByHql(String hql) {
		try {
			String queryString = hql;    
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {		
			throw re;
		} finally{
			//对应打开 这里关闭
			getSession().close();
		}
	}
	
	public boolean update(User user) {
		Transaction tran = null;
		Session session = null;
		try {
			session = getSession();
			tran = session.beginTransaction();
			session.update(user);
			tran.commit();
			return true;
		} catch (RuntimeException re) {
			if(tran != null) tran.rollback();
			throw re;
		} finally {
			session.close();
		}
	}
	
	public User getUser(int id) {
		return getSession().find(User.class, id);
	}
}
